﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI.HtmlControls; 
using Microsoft.Practices.Unity; 
using System.Reflection;
using System.Xml.Linq; 
using Exhibition.Common.CacheManager;
using Exhibition.Dao.ViewModel;
using Exhibition.Common.Helper;

namespace Exhibition.Service
{
    public class BasePage : System.Web.UI.Page
    {
         public int reqID = 0;
       
        public string Suffix = string.Empty;

        public SiteModel stmd { get; set; }
         
        protected override void OnLoad(EventArgs e)
        {

            if (!string.IsNullOrEmpty(Context.Request["id"]))
            {
                try
                {
                    reqID = Convert.ToInt32(Context.Request["id"]);
                }
                catch (Exception ex) {
                    LogHelper.Error(ex.Message);
                    JsHelper.Alert(this,"您胡乱修改了参数，我怎么给你计算！");
                }
            }

              stmd = CommonCacheManager.GetCacheData<SiteModel>("CurrentSite");
              if (stmd == null)
              {
                  stmd = CenterService.siteService.GetCurrentSite();
                  CommonCacheManager.AddCacheData<SiteModel>("CurrentSite", stmd, 180);
                 
              }
              WebTitle = stmd.WebName;
             
             
            base.OnLoad(e);
        }
        public string BuildUrl(string apath)
        {
            return "http://" + apath + Suffix;
        } 

        #region 注释掉
        //private void Content(HtmlControl htmlCtrl, string strTitle, string cssFile)
        //{
        //    //Title
        //    HtmlTitle title = new HtmlTitle();
        //    title.Text = strTitle;
        //    htmlCtrl.Controls.Add(title);

        //    ////Link/CSSfile:
        //    //HtmlLink cssLink = new HtmlLink();
        //    //cssLink.Href = cssFile;
        //    //cssLink.Attributes.Add("rel", "stylesheet");
        //    //cssLink.Attributes.Add("type", "text/css");
        //    //htmlCtrl.Controls.Add(cssLink);

        //    HtmlMeta
        //        //author = new HtmlMeta(), // author
        //  //  copyright = new HtmlMeta(), // copyright
        //    date = new HtmlMeta(), // date
        //    keywords = new HtmlMeta(), // keywords
        //    description = new HtmlMeta(); // description
        //    //robots = new HtmlMeta();// robots

        //    //author.Name = "Author";
        //    //author.Content = "Insus.NET";

        //    //copyright.Name = "Copyright";
        //    //copyright.Content = "Copyright 2008 Insus.NET";

        //    date.Name = "date";
        //    date.Content = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();

        //    keywords.Name = "keywords";
        //    keywords.Content = "Insus ";

        //    description.Name = "description";

        //    //robots.Name = "robots";
        //    //robots.Content = "all";


        //    string[] InsusWords = ""
        //      .Replace("\\r", string.Empty)
        //      .Replace("\\n", string.Empty)
        //      .Replace("&gt;br /&gt;", string.Empty)
        //      .Replace(",", string.Empty)
        //      .Replace("\\'", string.Empty)
        //      .Split(' ');

        //    foreach (string word in InsusWords)
        //        keywords.Content += word + ",";
        //    if (keywords.Content.ToString().Length > 1024)
        //    {
        //        keywords.Content = keywords.Content.Substring(0, keywords.Content.IndexOf(" ", 1024));
        //    }

        //    description.Content = "";
        //    if (description.Content.ToString().Length > 1024)
        //    {
        //        description.Content = description.Content.Substring(0, description.Content.IndexOf(" ", 1024));
        //    }

        //    //htmlCtrl.Controls.Add(author);
        //    //htmlCtrl.Controls.Add(copyright);
        //    htmlCtrl.Controls.Add(date);
        //    htmlCtrl.Controls.Add(keywords);
        //    htmlCtrl.Controls.Add(description);
        //    //htmlCtrl.Controls.Add(robots);
        //}
        #endregion
      
        public string WebTitle { get; set; }
         
         
         
         
        protected override void OnInit(EventArgs e)
        {
            

            //SQL防注入攻击
            if (Request.QueryString.Count > 0)
            {
                int loop1;
                NameValueCollection coll = Request.QueryString;
                String[] arr1 = coll.AllKeys;
                for (loop1 = 0; loop1 < arr1.Length; loop1++)
                {
                    String[] arr2 = coll.GetValues(arr1[loop1]);
                    int loop2;
                    for (loop2 = 0; loop2 < arr2.Length; loop2++)
                    {
                        string SQL_Repdata = ";--|exec|insert|select|delete|update|count|chr|mid|master|truncate|char|declare|create|drop";
                        String[] arr3 = SQL_Repdata.Split(char.Parse("|"));
                        int loop3;
                        for (loop3 = 0; loop3 < arr3.Length; loop3++)
                        {
                            if (arr2[loop2].ToLower().Trim().IndexOf(arr3[loop3]) > -1)
                            {
                                Response.Write("系统警告：你的行为被系统认定为[非法用户行为]！如有任何疑问,请和网站管理员联系。");
                                Response.End();
                            }
                        }
                    }
                }
            }
            base.OnInit(e);
        }

         
    }
}
